//
//  UITextField+Config.m
//  Fangxiaov
//
//  Created by safiri on 2017/3/23.
//  Copyright © 2017年 com.f. All rights reserved.
//

#import "UITextField+Config.h"

@implementation UITextField (Config)

- (void)configPlaceholderWithText:(nonnull NSString *)text AttrColor:(nonnull UIColor *)attrColor AttrFont:(nonnull UIFont *)attrFont {
    NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:text];
    [placeholder addAttribute:NSForegroundColorAttributeName
                        value:attrColor
                        range:NSMakeRange(0, text.length)];
    [placeholder addAttribute:NSFontAttributeName
                        value:attrFont
                        range:NSMakeRange(0, text.length)];
    self.attributedPlaceholder = placeholder;
}

- (void)selectAllText {
    UITextRange *range = [self textRangeFromPosition:self.beginningOfDocument toPosition:self.endOfDocument];
    [self setSelectedTextRange:range];
}

- (void)setSelectedRange:(NSRange)range {
    UITextPosition *beginning = self.beginningOfDocument;
    UITextPosition *startPosition = [self positionFromPosition:beginning offset:range.location];
    UITextPosition *endPosition = [self positionFromPosition:beginning offset:NSMaxRange(range)];
    UITextRange *selectionRange = [self textRangeFromPosition:startPosition toPosition:endPosition];
    [self setSelectedTextRange:selectionRange];
}
@end
